local skel = fk.CreateSkill {
  name = "emo__haomo",
  tags = {Skill.Limited},
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Finish
    and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    while not player.dead do
      local cid = room:getNCards(1)[1]
      room:moveCardTo(cid, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
      table.insert(cards, cid)
      local c = Fk:getCardById(cid)
      if c.is_damage_card or c.type == Card.TypeBasic then
        room:setCardEmotion(cid, "judgegood")
        room:delay(#cards < 6 and 700 or 100)
      else
        room:setCardEmotion(cid, "judgebad")
        break
      end
    end
    cards = table.filter(cards, function (id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 and player:isAlive() then
      room:delay(500)
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
    end
    room:cleanProcessingArea(cards, skel.name)
  end,
})

skel:addEffect(fk.AfterDrawPileShuffle, {
  can_refresh = function (self, event, target, player, data)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryGame)
  end,
})

Fk:loadTranslationTable{
  ["emo__haomo"] = "浩末",
  [":emo__haomo"] = "限定技，结束阶段，你可以重复亮出牌堆顶的牌直到未亮出基本牌或伤害类牌，然后获得这些牌；当牌堆洗牌后，此技能视为未发动过。",

  ["$emo__haomo1"] = "仰天光兮自列，招上帝兮我察！予有何罪？",
  ["$emo__haomo2"] = "龙登玄云，神栖昆仑；予有龙肝，欲禽神人佐之。",
}


return skel
